package top.lcm889.oj.offer.按数据结构分类.链表;

/**
 * @author Coder-lcm
 * @date 2021/2/5
 * 给定一个排序链表，删除所有重复的元素，使得每个元素只出现一次。
 *
 */
public class T83_删除排序链表中的重复节点元素 {
    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null){
            return head;
        }
        head.next = deleteDuplicates(head.next);
        return head.val == head.next.val ? head.next : head;
    }

    public static void main(String[] args) {
        ListNode res = deleteDuplicates(new ListNode(2131, new ListNode(12331, new ListNode(3131, new ListNode(3131)))));
        System.out.println(res.next.val);
        System.out.println(res.next.next.val);
    }
}
